import FcDesigner from '@form-create/designer';
import uniqueId from '@form-create/utils/lib/unique';
import {makeRequiredRule} from '@form-create/designer';

import TestUpload from "../../../components/TestUpload"
const label = '自定义上传';
const name = 'TestUpload';

export default {
  icon: 'icon-upload',
  label,
  name,
  rule() {
    return {
      type: name,
      component: TestUpload,
      field: "uoloadValue",
      title: label,
      info: '',
      $required: false,
      props: {
        action: '',
        onSuccess(res, file) {
          file.url = res.data.url;
        }
      }
    };
  },
  props() {
    return [ FcDesigner.makeOptionsRule('options'),
      {
        type: "Required",
        field: "formCreate$required",
        title: "是否必填"
      },{
      type: 'select',
      field: 'uploadType',
      title: '上传类型',
      value: 'image',
      options: [{label: '图片', value: 'image'}, {
        label: '文件',
        value: 'file'
      }, {
        label: '视频',
        value: 'video'
      }]
    }, {type: 'input', field: 'action', title: '上传的地址(必填)'}, {
      type: 'Struct',
      field: 'headers',
      title: '设置上传的请求头部',
      props: {defaultValue: {}}
    }, {type: 'switch', field: 'multiple', title: '是否支持多选文件'}, {
      type: 'Struct',
      field: 'data',
      title: '上传时附带的额外参数',
      props: {defaultValue: {}}
    }, {type: 'input', field: 'name', title: '上传的文件字段名'}, {
      type: 'switch',
      field: 'withCredentials',
      title: '支持发送 cookie 凭证信息'
    }, {type: 'input', field: 'accept', title: '接受上传的文件类型（thumbnail-mode 模式下此参数无效）'}, {
      type: 'switch',
      field: 'autoUpload',
      title: '是否在选取文件后立即进行上传',
      value: true
    }, {
      type: 'switch',
      field: 'disabled',
      title: '是否禁用'
    }, {
      type: 'inputNumber',
      field: 'limit',
      title: '最大允许上传个数',
      props: {min:0},
    }];
  }
};
